package com.lishe.lishe.lishe.module.excitation.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.excitation.bean.WelfareObject;
import com.lishe.lishe.lishe.utils.TimeUtils;

import java.util.List;

/**
 * Created by shino on 2017/11/24.
 */

public class MineWelFareAdapter extends RecyclerviewBaseAdapter {
    private Activity context;
    private List<WelfareObject> welfareObjectList;

    public MineWelFareAdapter(Activity context, List<WelfareObject> welfareObjectList) {
        this.context = context;
        this.welfareObjectList = welfareObjectList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_welfare, null);
        view.setLayoutParams(params);
        MineWelFareHolder mineWelFareHolder = new MineWelFareHolder(view);
        return mineWelFareHolder;
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder, int position) {
        MineWelFareHolder myHolder = (MineWelFareHolder) holder;
        WelfareObject welfareObject = welfareObjectList.get(position);
        myHolder.welfare_name.setText(welfareObject.getWelfareName());
        myHolder.welfare_type.setText(welfareObject.getWelfareFormToString());
        myHolder.welfare_status.setText(welfareObject.getReceiveFlagToString());
        myHolder.welfare_time.setText(TimeUtils.longToyyyyMMdd(welfareObject.getSendTime()));
        ImageLoaderUtils.displayImage(context, welfareObject.getImgUrl(), myHolder.image);
    }

    @Override
    public int getItemCountMy() {
        return welfareObjectList == null ? 0 : welfareObjectList.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    class MineWelFareHolder extends RecyclerView.ViewHolder {

        private ImageView image;
        private TextView welfare_name;
        private TextView welfare_type;
        private TextView welfare_time;
        private TextView welfare_status;

        public MineWelFareHolder(View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.image);
            welfare_name = itemView.findViewById(R.id.welfare_name);
            welfare_type = itemView.findViewById(R.id.welfare_type);
            welfare_time = itemView.findViewById(R.id.welfare_time);
            welfare_status = itemView.findViewById(R.id.welfare_status);
        }
    }

}
